/*
 * Copyright 2009 BioTeam Inc
 * 
 * Licensed under License GNU LESSER GENERAL PUBLIC LICENSE version 3.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.gnu.org/copyleft/lesser.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package net.bioteam.appweb.gwt.apps.client.program;

import net.bioteam.appweb.gwt.apps.client.datatree.DataTreeDataSource;
import net.bioteam.appweb.gwt.apps.client.datatree.DataTreeGrid;
import net.bioteam.appweb.gwt.apps.client.datatree.DataTreeGrid.ViewState;

import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.events.CloseClickHandler;
import com.smartgwt.client.widgets.events.CloseClientEvent;
import com.smartgwt.client.widgets.form.fields.TextItem;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.tree.TreeNode;

public class ServerFileWindow extends Window
{
	
	TextItem tx;
	
	
	public TextItem getTx()
	{
		return tx;
	}


	public void setTx(TextItem tx)
	{
		this.tx = tx;
	}


	public ServerFileWindow()
	{
		setWidth(360);
		setHeight(360);
		setTitle("Select Server Files");
		setShowMinimizeButton(false);
		setIsModal(true);
		centerInPage();
		setAutoSize(true);
		//setLayoutMargin(30);
		//setMembersMargin(30);
		
		addCloseClickHandler(new CloseClickHandler(){

			public void onCloseClick(CloseClientEvent event)
			{
				ServerFileWindow.this.hide();
			}});
		
		
		VLayout v1=new VLayout();
		v1.setMembersMargin(20);
		v1.setWidth100();
		
		final DataTreeGrid treeGrid=new DataTreeGrid(ViewState.SELECT);
		treeGrid.setHeight(330);
		treeGrid.setWidth100();
		treeGrid.setOverflow(Overflow.AUTO);
		treeGrid.setShowEdges(false);
		
		treeGrid.setLayoutAlign(Alignment.CENTER);
		v1.addMember(treeGrid);
		//addItem(treeGrid);
		
//		LayoutSpacer spacer=new LayoutSpacer();
//		spacer.setHeight(10);
//		addItem(spacer);
	
		HLayout hb1=new HLayout();
		hb1.setHeight(30);
		hb1.setWidth(60);
		//hb1.setBackgroundColor("yellow");
		hb1.setLayoutAlign(Alignment.CENTER);
		
		
		IButton ok=new IButton("OK");
		//ok.setLayoutAlign(Alignment.CENTER);
		ok.addClickHandler(new ClickHandler(){

			public void onClick(ClickEvent event)
			{
				if (tx==null)
					return;
				TreeNode treeNode=(TreeNode)treeGrid.getSelectedRecord();
				if (treeNode==null)
					return;
				String path=treeGrid.getTree().getPath(treeNode);
				tx.setValue(DataTreeDataSource.translatePath(path));
				ServerFileWindow.this.hide();
			}});
		
		hb1.addMember(ok);
		IButton cancel=new IButton("Cancel");
		//cancel.setLayoutAlign(Alignment.CENTER);
		cancel.addClickHandler(new ClickHandler(){

			public void onClick(ClickEvent event)
			{
				ServerFileWindow.this.hide();
			}});
		hb1.addMember(cancel);
		v1.addMember(hb1);
		
		addItem(v1);
	}
	
	
}
